unit Winsoft.Android.Usb;

interface


{$IFDEF ANDROID}
uses

  Androidapi.JNIBridge,
  Androidapi.JNI.App,
  Androidapi.JNI.GraphicsContentViewText,
  Androidapi.JNI.JavaTypes,
  Androidapi.JNI.Os;


type
  JUsbAccessory = interface; {android/hardware/usb/UsbAccessory}
  JUsbConfiguration = interface; {android/hardware/usb/UsbConfiguration}
  JUsbConstants = interface; {android/hardware/usb/UsbConstants}
  JUsbDevice = interface; {android/hardware/usb/UsbDevice}
  JUsbDeviceConnection = interface; {android/hardware/usb/UsbDeviceConnection}
  JUsbEndpoint = interface; {android/hardware/usb/UsbEndpoint}
  JUsbInterface = interface; {android/hardware/usb/UsbInterface}
  JUsbManager = interface; {android/hardware/usb/UsbManager}
  JUsbRequest = interface; {android/hardware/usb/UsbRequest}

  JUsbAccessoryClass = interface(JObjectClass)
    ['{41026DD2-7F6D-4340-B3AE-71A7FFC6946D}']
    function _GetCREATOR: JParcelable_Creator;
    procedure _SetCREATOR(Value: JParcelable_Creator);
    property CREATOR: JParcelable_Creator read _GetCREATOR write _SetCREATOR;
  end;

  [JavaSignature('android/hardware/usb/UsbAccessory')]
  JUsbAccessory = interface(JObject)
    ['{6BDDD952-F140-4E5E-94B8-977570AF6774}']
    function describeContents: Integer; cdecl;
    function equals(obj: JObject): Boolean; cdecl;
    function getDescription: JString; cdecl;
    function getManufacturer: JString; cdecl;
    function getModel: JString; cdecl;
    function getSerial: JString; cdecl;
    function getUri: JString; cdecl;
    function getVersion: JString; cdecl;
    function hashCode: Integer; cdecl;
    function toString: JString; cdecl;
    procedure writeToParcel(parcel: JParcel; flags: Integer); cdecl;
  end;

  TJUsbAccessory = class(TJavaGenericImport<JUsbAccessoryClass, JUsbAccessory>)
  end;

  JUsbConfigurationClass = interface(JObjectClass)
    ['{3A14D202-D06A-4EDA-999B-5E061492A271}']
    function _GetCREATOR: JParcelable_Creator;
    procedure _SetCREATOR(Value: JParcelable_Creator);
    property CREATOR: JParcelable_Creator read _GetCREATOR write _SetCREATOR;
  end;

  [JavaSignature('android/hardware/usb/UsbConfiguration')]
  JUsbConfiguration = interface(JObject)
    ['{2EE81492-51FA-4201-A376-11056480DAB0}']
    function describeContents: Integer; cdecl;
    function getId: Integer; cdecl;
    function getInterface(&index: Integer): JUsbInterface; cdecl;
    function getInterfaceCount: Integer; cdecl;
    function getMaxPower: Integer; cdecl;
    function getName: JString; cdecl;
    function isRemoteWakeup: Boolean; cdecl;
    function isSelfPowered: Boolean; cdecl;
    function toString: JString; cdecl;
    procedure writeToParcel(parcel: JParcel; flags: Integer); cdecl;
  end;

  TJUsbConfiguration = class(TJavaGenericImport<JUsbConfigurationClass, JUsbConfiguration>)
  end;

  JUsbConstantsClass = interface(JObjectClass)
    ['{64918D4F-C5E5-4FE2-AACD-62CC33661BC3}']
    function _GetUSB_CLASS_APP_SPEC: Integer;
    function _GetUSB_CLASS_AUDIO: Integer;
    function _GetUSB_CLASS_CDC_DATA: Integer;
    function _GetUSB_CLASS_COMM: Integer;
    function _GetUSB_CLASS_CONTENT_SEC: Integer;
    function _GetUSB_CLASS_CSCID: Integer;
    function _GetUSB_CLASS_HID: Integer;
    function _GetUSB_CLASS_HUB: Integer;
    function _GetUSB_CLASS_MASS_STORAGE: Integer;
    function _GetUSB_CLASS_MISC: Integer;
    function _GetUSB_CLASS_PER_INTERFACE: Integer;
    function _GetUSB_CLASS_PHYSICA: Integer;
    function _GetUSB_CLASS_PRINTER: Integer;
    function _GetUSB_CLASS_STILL_IMAGE: Integer;
    function _GetUSB_CLASS_VENDOR_SPEC: Integer;
    function _GetUSB_CLASS_VIDEO: Integer;
    function _GetUSB_CLASS_WIRELESS_CONTROLLER: Integer;
    function _GetUSB_DIR_IN: Integer;
    function _GetUSB_DIR_OUT: Integer;
    function _GetUSB_ENDPOINT_DIR_MASK: Integer;
    function _GetUSB_ENDPOINT_NUMBER_MASK: Integer;
    function _GetUSB_ENDPOINT_XFERTYPE_MASK: Integer;
    function _GetUSB_ENDPOINT_XFER_BULK: Integer;
    function _GetUSB_ENDPOINT_XFER_CONTROL: Integer;
    function _GetUSB_ENDPOINT_XFER_INT: Integer;
    function _GetUSB_ENDPOINT_XFER_ISOC: Integer;
    function _GetUSB_INTERFACE_SUBCLASS_BOOT: Integer;
    function _GetUSB_SUBCLASS_VENDOR_SPEC: Integer;
    function _GetUSB_TYPE_CLASS: Integer;
    function _GetUSB_TYPE_MASK: Integer;
    function _GetUSB_TYPE_RESERVED: Integer;
    function _GetUSB_TYPE_STANDARD: Integer;
    function _GetUSB_TYPE_VENDOR: Integer;
    function init: JUsbConstants; cdecl;
    property USB_CLASS_APP_SPEC: Integer read _GetUSB_CLASS_APP_SPEC;
    property USB_CLASS_AUDIO: Integer read _GetUSB_CLASS_AUDIO;
    property USB_CLASS_CDC_DATA: Integer read _GetUSB_CLASS_CDC_DATA;
    property USB_CLASS_COMM: Integer read _GetUSB_CLASS_COMM;
    property USB_CLASS_CONTENT_SEC: Integer read _GetUSB_CLASS_CONTENT_SEC;
    property USB_CLASS_CSCID: Integer read _GetUSB_CLASS_CSCID;
    property USB_CLASS_HID: Integer read _GetUSB_CLASS_HID;
    property USB_CLASS_HUB: Integer read _GetUSB_CLASS_HUB;
    property USB_CLASS_MASS_STORAGE: Integer read _GetUSB_CLASS_MASS_STORAGE;
    property USB_CLASS_MISC: Integer read _GetUSB_CLASS_MISC;
    property USB_CLASS_PER_INTERFACE: Integer read _GetUSB_CLASS_PER_INTERFACE;
    property USB_CLASS_PHYSICA: Integer read _GetUSB_CLASS_PHYSICA;
    property USB_CLASS_PRINTER: Integer read _GetUSB_CLASS_PRINTER;
    property USB_CLASS_STILL_IMAGE: Integer read _GetUSB_CLASS_STILL_IMAGE;
    property USB_CLASS_VENDOR_SPEC: Integer read _GetUSB_CLASS_VENDOR_SPEC;
    property USB_CLASS_VIDEO: Integer read _GetUSB_CLASS_VIDEO;
    property USB_CLASS_WIRELESS_CONTROLLER: Integer read _GetUSB_CLASS_WIRELESS_CONTROLLER;
    property USB_DIR_IN: Integer read _GetUSB_DIR_IN;
    property USB_DIR_OUT: Integer read _GetUSB_DIR_OUT;
    property USB_ENDPOINT_DIR_MASK: Integer read _GetUSB_ENDPOINT_DIR_MASK;
    property USB_ENDPOINT_NUMBER_MASK: Integer read _GetUSB_ENDPOINT_NUMBER_MASK;
    property USB_ENDPOINT_XFERTYPE_MASK: Integer read _GetUSB_ENDPOINT_XFERTYPE_MASK;
    property USB_ENDPOINT_XFER_BULK: Integer read _GetUSB_ENDPOINT_XFER_BULK;
    property USB_ENDPOINT_XFER_CONTROL: Integer read _GetUSB_ENDPOINT_XFER_CONTROL;
    property USB_ENDPOINT_XFER_INT: Integer read _GetUSB_ENDPOINT_XFER_INT;
    property USB_ENDPOINT_XFER_ISOC: Integer read _GetUSB_ENDPOINT_XFER_ISOC;
    property USB_INTERFACE_SUBCLASS_BOOT: Integer read _GetUSB_INTERFACE_SUBCLASS_BOOT;
    property USB_SUBCLASS_VENDOR_SPEC: Integer read _GetUSB_SUBCLASS_VENDOR_SPEC;
    property USB_TYPE_CLASS: Integer read _GetUSB_TYPE_CLASS;
    property USB_TYPE_MASK: Integer read _GetUSB_TYPE_MASK;
    property USB_TYPE_RESERVED: Integer read _GetUSB_TYPE_RESERVED;
    property USB_TYPE_STANDARD: Integer read _GetUSB_TYPE_STANDARD;
    property USB_TYPE_VENDOR: Integer read _GetUSB_TYPE_VENDOR;
  end;

  [JavaSignature('android/hardware/usb/UsbConstants')]
  JUsbConstants = interface(JObject)
    ['{AAEE26FD-823E-4BE9-98C4-83F85A18F636}']
  end;

  TJUsbConstants = class(TJavaGenericImport<JUsbConstantsClass, JUsbConstants>)
  end;

  JUsbDeviceClass = interface(JObjectClass)
    ['{F15C59C8-9C54-444D-8205-EFEF1A78223E}']
    function _GetCREATOR: JParcelable_Creator;
    procedure _SetCREATOR(Value: JParcelable_Creator);
    function getDeviceId(name: JString): Integer; cdecl;
    function getDeviceName(id: Integer): JString; cdecl;
    property CREATOR: JParcelable_Creator read _GetCREATOR write _SetCREATOR;
  end;

  [JavaSignature('android/hardware/usb/UsbDevice')]
  JUsbDevice = interface(JObject)
    ['{F80F0C53-349A-4E94-9F61-3DDB051A4955}']
    function describeContents: Integer; cdecl;
    function equals(o: JObject): Boolean; cdecl;
    function getConfiguration(&index: Integer): JUsbConfiguration; cdecl;
    function getConfigurationCount: Integer; cdecl;
    function getDeviceClass: Integer; cdecl;
    function getDeviceId: Integer; cdecl;
    function getDeviceName: JString; cdecl;
    function getDeviceProtocol: Integer; cdecl;
    function getDeviceSubclass: Integer; cdecl;
    function getInterface(&index: Integer): JUsbInterface; cdecl;
    function getInterfaceCount: Integer; cdecl;
    function getManufacturerName: JString; cdecl;
    function getProductId: Integer; cdecl;
    function getProductName: JString; cdecl;
    function getSerialNumber: JString; cdecl;
    function getVendorId: Integer; cdecl;
    function getVersion: JString; cdecl;
    function hashCode: Integer; cdecl;
    function toString: JString; cdecl;
    procedure writeToParcel(parcel: JParcel; flags: Integer); cdecl;
  end;

  TJUsbDevice = class(TJavaGenericImport<JUsbDeviceClass, JUsbDevice>)
  end;

  JUsbDeviceConnectionClass = interface(JObjectClass)
    ['{E623140B-634D-4035-A260-3382B97C1166}']
  end;

  [JavaSignature('android/hardware/usb/UsbDeviceConnection')]
  JUsbDeviceConnection = interface(JObject)
    ['{9D0955E1-4CB4-477E-9EA9-EA7DA30C73E6}']
    function bulkTransfer(endpoint: JUsbEndpoint; buffer: TJavaArray<Byte>; length: Integer; timeout: Integer): Integer; cdecl; overload;
    function bulkTransfer(endpoint: JUsbEndpoint; buffer: TJavaArray<Byte>; offset: Integer; length: Integer; timeout: Integer): Integer; cdecl; overload;
    function claimInterface(intf: JUsbInterface; force: Boolean): Boolean; cdecl;
    procedure close; cdecl;
    function controlTransfer(requestType: Integer; request: Integer; value: Integer; &index: Integer; buffer: TJavaArray<Byte>; length: Integer; timeout: Integer): Integer; cdecl; overload;
    function controlTransfer(requestType: Integer; request: Integer; value: Integer; &index: Integer; buffer: TJavaArray<Byte>; offset: Integer; length: Integer; timeout: Integer): Integer; cdecl; overload;
    function getFileDescriptor: Integer; cdecl;
    function getRawDescriptors: TJavaArray<Byte>; cdecl;
    function getSerial: JString; cdecl;
    function releaseInterface(intf: JUsbInterface): Boolean; cdecl;
    function requestWait: JUsbRequest; cdecl; overload;
    function requestWait(timeout: Int64): JUsbRequest; cdecl; overload;
    function setConfiguration(configuration: JUsbConfiguration): Boolean; cdecl;
    function setInterface(intf: JUsbInterface): Boolean; cdecl;
  end;

  TJUsbDeviceConnection = class(TJavaGenericImport<JUsbDeviceConnectionClass, JUsbDeviceConnection>)
  end;

  JUsbEndpointClass = interface(JObjectClass)
    ['{04F540D0-FE12-469C-B60B-C138E9A0DC15}']
    function _GetCREATOR: JParcelable_Creator;
    procedure _SetCREATOR(Value: JParcelable_Creator);
    property CREATOR: JParcelable_Creator read _GetCREATOR write _SetCREATOR;
  end;

  [JavaSignature('android/hardware/usb/UsbEndpoint')]
  JUsbEndpoint = interface(JObject)
    ['{FA0E741F-B366-495E-ADB8-0E123F671156}']
    function describeContents: Integer; cdecl;
    function getAddress: Integer; cdecl;
    function getAttributes: Integer; cdecl;
    function getDirection: Integer; cdecl;
    function getEndpointNumber: Integer; cdecl;
    function getInterval: Integer; cdecl;
    function getMaxPacketSize: Integer; cdecl;
    function getType: Integer; cdecl;
    function toString: JString; cdecl;
    procedure writeToParcel(parcel: JParcel; flags: Integer); cdecl;
  end;

  TJUsbEndpoint = class(TJavaGenericImport<JUsbEndpointClass, JUsbEndpoint>)
  end;

  JUsbInterfaceClass = interface(JObjectClass)
    ['{BE86F03B-8597-4BCA-8954-F59EF065E666}']
    function _GetCREATOR: JParcelable_Creator;
    procedure _SetCREATOR(Value: JParcelable_Creator);
    property CREATOR: JParcelable_Creator read _GetCREATOR write _SetCREATOR;
  end;

  [JavaSignature('android/hardware/usb/UsbInterface')]
  JUsbInterface = interface(JObject)
    ['{1E6D2E78-3A68-4DB7-9283-9EA05BCA9151}']
    function describeContents: Integer; cdecl;
    function getAlternateSetting: Integer; cdecl;
    function getEndpoint(&index: Integer): JUsbEndpoint; cdecl;
    function getEndpointCount: Integer; cdecl;
    function getId: Integer; cdecl;
    function getInterfaceClass: Integer; cdecl;
    function getInterfaceProtocol: Integer; cdecl;
    function getInterfaceSubclass: Integer; cdecl;
    function getName: JString; cdecl;
    function toString: JString; cdecl;
    procedure writeToParcel(parcel: JParcel; flags: Integer); cdecl;
  end;

  TJUsbInterface = class(TJavaGenericImport<JUsbInterfaceClass, JUsbInterface>)
  end;

  JUsbManagerClass = interface(JObjectClass)
    ['{601C584D-F23F-430B-90CC-B626EE9E0632}']
    function _GetACTION_USB_ACCESSORY_ATTACHED: JString;
    function _GetACTION_USB_ACCESSORY_DETACHED: JString;
    function _GetACTION_USB_DEVICE_ATTACHED: JString;
    function _GetACTION_USB_DEVICE_DETACHED: JString;
    function _GetEXTRA_ACCESSORY: JString;
    function _GetEXTRA_DEVICE: JString;
    function _GetEXTRA_PERMISSION_GRANTED: JString;
    property ACTION_USB_ACCESSORY_ATTACHED: JString read _GetACTION_USB_ACCESSORY_ATTACHED;
    property ACTION_USB_ACCESSORY_DETACHED: JString read _GetACTION_USB_ACCESSORY_DETACHED;
    property ACTION_USB_DEVICE_ATTACHED: JString read _GetACTION_USB_DEVICE_ATTACHED;
    property ACTION_USB_DEVICE_DETACHED: JString read _GetACTION_USB_DEVICE_DETACHED;
    property EXTRA_ACCESSORY: JString read _GetEXTRA_ACCESSORY;
    property EXTRA_DEVICE: JString read _GetEXTRA_DEVICE;
    property EXTRA_PERMISSION_GRANTED: JString read _GetEXTRA_PERMISSION_GRANTED;
  end;

  [JavaSignature('android/hardware/usb/UsbManager')]
  JUsbManager = interface(JObject)
    ['{46D7C03C-0934-4BBA-858C-979329B1CAA3}']
    function getAccessoryList: TJavaObjectArray<JUsbAccessory>; cdecl;
    function getDeviceList: JHashMap; cdecl;
    function hasPermission(device: JUsbDevice): Boolean; cdecl; overload;
    function hasPermission(accessory: JUsbAccessory): Boolean; cdecl; overload;
    function openAccessory(accessory: JUsbAccessory): JParcelFileDescriptor; cdecl;
    function openDevice(device: JUsbDevice): JUsbDeviceConnection; cdecl;
    procedure requestPermission(device: JUsbDevice; pi: JPendingIntent); cdecl; overload;
    procedure requestPermission(accessory: JUsbAccessory; pi: JPendingIntent); cdecl; overload;
  end;

  TJUsbManager = class(TJavaGenericImport<JUsbManagerClass, JUsbManager>)
  end;

  JUsbRequestClass = interface(JObjectClass)
    ['{B96BF7BD-51E8-4A64-BFBD-81DB2C4CCA12}']
    function init: JUsbRequest; cdecl;
  end;

  [JavaSignature('android/hardware/usb/UsbRequest')]
  JUsbRequest = interface(JObject)
    ['{D7212EC4-3E4A-427E-BBBD-94F5129ABA82}']
    function cancel: Boolean; cdecl;
    procedure close; cdecl;
    function getClientData: JObject; cdecl;
    function getEndpoint: JUsbEndpoint; cdecl;
    function initialize(connection: JUsbDeviceConnection; endpoint: JUsbEndpoint): Boolean; cdecl;
    function queue(buffer: JByteBuffer; length: Integer): Boolean; cdecl; overload; deprecated;
    function queue(buffer: JByteBuffer): Boolean; cdecl; overload;
    procedure setClientData(data: JObject); cdecl;
  end;

  TJUsbRequest = class(TJavaGenericImport<JUsbRequestClass, JUsbRequest>)
  end;

const
  TJUsbConstants_USB_CLASS_APP_SPEC = 254;
  TJUsbConstants_USB_CLASS_AUDIO = 1;
  TJUsbConstants_USB_CLASS_CDC_DATA = 10;
  TJUsbConstants_USB_CLASS_COMM = 2;
  TJUsbConstants_USB_CLASS_CONTENT_SEC = 13;
  TJUsbConstants_USB_CLASS_CSCID = 11;
  TJUsbConstants_USB_CLASS_HID = 3;
  TJUsbConstants_USB_CLASS_HUB = 9;
  TJUsbConstants_USB_CLASS_MASS_STORAGE = 8;
  TJUsbConstants_USB_CLASS_MISC = 239;
  TJUsbConstants_USB_CLASS_PER_INTERFACE = 0;
  TJUsbConstants_USB_CLASS_PHYSICA = 5;
  TJUsbConstants_USB_CLASS_PRINTER = 7;
  TJUsbConstants_USB_CLASS_STILL_IMAGE = 6;
  TJUsbConstants_USB_CLASS_VENDOR_SPEC = 255;
  TJUsbConstants_USB_CLASS_VIDEO = 14;
  TJUsbConstants_USB_CLASS_WIRELESS_CONTROLLER = 224;
  TJUsbConstants_USB_DIR_IN = 128;
  TJUsbConstants_USB_DIR_OUT = 0;
  TJUsbConstants_USB_ENDPOINT_DIR_MASK = 128;
  TJUsbConstants_USB_ENDPOINT_NUMBER_MASK = 15;
  TJUsbConstants_USB_ENDPOINT_XFERTYPE_MASK = 3;
  TJUsbConstants_USB_ENDPOINT_XFER_BULK = 2;
  TJUsbConstants_USB_ENDPOINT_XFER_CONTROL = 0;
  TJUsbConstants_USB_ENDPOINT_XFER_INT = 3;
  TJUsbConstants_USB_ENDPOINT_XFER_ISOC = 1;
  TJUsbConstants_USB_INTERFACE_SUBCLASS_BOOT = 1;
  TJUsbConstants_USB_SUBCLASS_VENDOR_SPEC = 255;
  TJUsbConstants_USB_TYPE_CLASS = 32;
  TJUsbConstants_USB_TYPE_MASK = 96;
  TJUsbConstants_USB_TYPE_RESERVED = 96;
  TJUsbConstants_USB_TYPE_STANDARD = 0;
  TJUsbConstants_USB_TYPE_VENDOR = 64;

  TJUsbManager_ACTION_USB_ACCESSORY_ATTACHED = 'android.hardware.usb.action.USB_ACCESSORY_ATTACHED';
  TJUsbManager_ACTION_USB_ACCESSORY_DETACHED = 'android.hardware.usb.action.USB_ACCESSORY_DETACHED';
  TJUsbManager_ACTION_USB_DEVICE_ATTACHED = 'android.hardware.usb.action.USB_DEVICE_ATTACHED';
  TJUsbManager_ACTION_USB_DEVICE_DETACHED = 'android.hardware.usb.action.USB_DEVICE_DETACHED';
  TJUsbManager_EXTRA_ACCESSORY = 'accessory';
  TJUsbManager_EXTRA_DEVICE = 'device';
  TJUsbManager_EXTRA_PERMISSION_GRANTED = 'permission';

implementation

procedure RegisterTypes;
begin
  TRegTypes.RegisterType('Winsoft.Android.Usb.JUsbAccessory', TypeInfo(Winsoft.Android.Usb.JUsbAccessory));
  TRegTypes.RegisterType('Winsoft.Android.Usb.JUsbConfiguration', TypeInfo(Winsoft.Android.Usb.JUsbConfiguration));
  TRegTypes.RegisterType('Winsoft.Android.Usb.JUsbConstants', TypeInfo(Winsoft.Android.Usb.JUsbConstants));
  TRegTypes.RegisterType('Winsoft.Android.Usb.JUsbDevice', TypeInfo(Winsoft.Android.Usb.JUsbDevice));
  TRegTypes.RegisterType('Winsoft.Android.Usb.JUsbDeviceConnection', TypeInfo(Winsoft.Android.Usb.JUsbDeviceConnection));
  TRegTypes.RegisterType('Winsoft.Android.Usb.JUsbEndpoint', TypeInfo(Winsoft.Android.Usb.JUsbEndpoint));
  TRegTypes.RegisterType('Winsoft.Android.Usb.JUsbInterface', TypeInfo(Winsoft.Android.Usb.JUsbInterface));
  TRegTypes.RegisterType('Winsoft.Android.Usb.JUsbManager', TypeInfo(Winsoft.Android.Usb.JUsbManager));
  TRegTypes.RegisterType('Winsoft.Android.Usb.JUsbRequest', TypeInfo(Winsoft.Android.Usb.JUsbRequest));
end;

initialization
  RegisterTypes;

{$ELSE}

implementation
{$ENDIF}

end.